package br.com.materiais.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import br.com.materiais.dao.LoginDao;
import br.com.materiais.form.LoginForm;
import br.com.materiais.model.LoginModel;

public class LoginAction extends Action
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1945396002297021184L;
   
	@Override 
	public ActionForward execute(ActionMapping map,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception
	{
		LoginForm loginForm = ((LoginForm)form);
		LoginModel login = loginForm.getLogin();
		String ret = new LoginDao().getUsuario(login.getUsuario(),login.getSenha());
	    try
	    {
		   if(ret.equals("ok"))
	         return map.findForward("ok");
		}
		catch(Exception e )
		{
		 	return map.findForward("erro");
		}
		return map.findForward("ok");
	}
}
